//
//  MyActiviCollection.m
//  12.30_homework_豆瓣电影MVC
//
//  Created by dllo on 16/1/8.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "MyActiviCollection.h"
#import "LXC_DataBaseHandle.h"
#import "ActivityModel.h"

@interface MyActiviCollection () <UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrModel;

@end

@implementation MyActiviCollection

- (void)dealloc {
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"我的活动";
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:(UITableViewStylePlain)];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.arrModel = [[LXC_DataBaseHandle shareDataBaseHandle] selectModel];
    
    self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

#pragma mark - tableView 编辑
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
    [super setEditing:editing animated:animated];
    [_tableView setEditing:editing animated:animated];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ActivityModel *model = [ActivityModel activityModel];
    model = _arrModel[indexPath.row];
    
    [_arrModel removeObjectAtIndex:indexPath.row];
    
    [[LXC_DataBaseHandle shareDataBaseHandle] deleteModel:model.title tabName:@"MyActivityCollection"];
    
    [_tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
    
   
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrModel.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];

        
    ActivityModel *model = _arrModel[indexPath.row];
    cell.textLabel.text = model.title;

    

    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
